package advanced.practice._1014;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Map<Integer,Float>aMap=new HashMap<>();

        int N=sc.nextInt();
        for(int i=0;i<N;i++){
            aMap.put(sc.nextInt(),sc.nextFloat());
        }

        N=sc.nextInt();
        for(int i=0;i<N;i++){
            int key=sc.nextInt();
            float value=sc.nextFloat();
            if(aMap.containsKey(key)){
                value+=aMap.get(key);
            }
            aMap.put(key,value);
        }

        List<Map.Entry<Integer,Float>> list=new ArrayList<>();
        list.addAll(aMap.entrySet());
        list.sort((o1, o2) -> o2.getKey()-o1.getKey());

        StringBuilder builder=new StringBuilder();
        int count=0;
        for(Map.Entry<Integer,Float> entry:list){
            if(entry.getValue()==0){
                continue;
            }

            builder.append(String.format(" %s %.1f",entry.getKey(),entry.getValue()));
            count++;
        }
        builder.insert(0,count);
        System.out.println(builder.toString().trim());
    }
}
